perf(allocator): add #[cold] annotations to error handling functions#18181
Merged
graphite-app[bot] merged 1 commit intomainfrom Jan 18, 2026
Merged
perf(allocator): add #[cold] annotations to error handling functions#18181graphite-app[bot] merged 1 commit intomainfrom
graphite-app[bot] merged 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds performance optimization attributes (#[cold] and #[inline(never)]) to error handling and panic functions in the oxc_allocator crate to improve branch prediction and code layout for hot allocation paths.
Changes:
- Added
#[cold]attribute toallocation_size_overflowinbump.rs(already had#[inline(never)]) - Added both
#[cold]and#[inline(never)]attributes tonew_layout_errandhandle_alloc_errorinbumpalo_alloc.rs - Added both
#[cold]and#[inline(never)]attributes tocapacity_overflowinvec2/raw_vec.rs
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
crates/oxc_allocator/src/bump.rs |
Added #[cold] to allocation_size_overflow function |
crates/oxc_allocator/src/bumpalo_alloc.rs |
Added #[cold] and #[inline(never)] to new_layout_err and handle_alloc_error functions |
crates/oxc_allocator/src/vec2/raw_vec.rs |
Added #[cold] and #[inline(never)] to capacity_overflow function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will not alter performance
Comparing Footnotes
|
Member
Author
Merge activity
|
…18181) ## Summary - Add `#[cold]` and `#[inline(never)]` annotations to error/panic functions in oxc_allocator - Improves branch prediction and code layout for hot allocation paths ### Functions annotated | File | Function | Change | |------|----------|--------| | `bump.rs` | `allocation_size_overflow` | Added `#[cold]` | | `bumpalo_alloc.rs` | `new_layout_err` | Added `#[cold]` + `#[inline(never)]` | | `bumpalo_alloc.rs` | `handle_alloc_error` | Added `#[cold]` + `#[inline(never)]` | | `vec2/raw_vec.rs` | `capacity_overflow` | Added `#[cold]` + `#[inline(never)]` | ### Impact The `#[cold]` attribute tells the compiler to: 1. Assume branches leading to these functions are unlikely 2. Move cold code away from hot paths (improves i-cache locality) 3. Avoid inlining cold functions into hot callers ## Test plan - [x] `cargo test -p oxc_allocator` passes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
0dd3702 to
46cd73d
Compare
This was referenced Apr 2, 2026
overlookmotel
added a commit
that referenced
this pull request
Apr 2, 2026
#18168 copied `bumpalo`'s code for `Bump` into `oxc_allocator` crate. #18172, #18181, and #18234 made a few improvements to the implementation. However, #18168 removed various things, and altered others. Notably, it removed the`MIN_ALIGN` generic param, which we definitely want to keep. I'm going to be working on the allocator, and would like to start with a clean slate, beginning with the "known good" implementation of `bumpalo`. This PR removes the previous modified `bumpalo` implementation, and copies latest version of `bumpalo` from main branch into the repo. It then makes the absolute minimum changes necessary just to make CI pass. Note: Unlike #18168, this PR keeps all the doctests for `Bump`, using a trick of adding the crate to it's own `dev-dependencies` with `testing` feature enabled, and exposing `Bump` only with that feature. This PR is broken into multiple commits, so we have an exact "trail of breadcrumbs" of how we've diverged from `bumpalo`. I intend to manually merge this PR, so that record remains on Github (instead of Graphite squashing all the commits). Later PRs in this stack reapply the changes made in #18172, #18181, and #18234 on top of the fresh base implementation. This PR is a small perf regression, but that will be won back once those other changes are reapplied.
graphite-app bot
pushed a commit
that referenced
this pull request
Apr 2, 2026
Repeat of #18181. #20963 wiped all changes to `bumpalo_alloc.rs`, going back to a fresh copy of `bumpalo`. Re-apply changes from #18181 which were lost in the process - marking error handling functions as `#[cold]`. This PR differs from #18181 in one minor respect. `new_layout_err` is not marked `#[inline(never)]` in this PR. The function is a no-op (unconditionally returns a ZST), so we do want it inlined, but with the`#[cold]`attribute to hint to compiler that it's a cold path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#[cold]and#[inline(never)]annotations to error/panic functions in oxc_allocatorFunctions annotated
bump.rsallocation_size_overflow#[cold]bumpalo_alloc.rsnew_layout_err#[cold]+#[inline(never)]bumpalo_alloc.rshandle_alloc_error#[cold]+#[inline(never)]vec2/raw_vec.rscapacity_overflow#[cold]+#[inline(never)]Impact
The
#[cold]attribute tells the compiler to:Test plan
cargo test -p oxc_allocatorpasses🤖 Generated with Claude Code